<?php

namespace common\modules\zt\models\beierban;

use common\behaviors\TimestampBehavior;
use common\components\ActiveRecord;
use Yii;
use yii\db\Expression;

/**
 * This is the model class for table "zt_beierban_item".
 *
 * @property integer $id
 * @property integer $save_id
 * @property string $openid
 * @property string $items
 * @property string $client_ip
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $created_by
 * @property integer $updated_by
 */
class Item extends ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'zt_beierban_item';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['save_id', 'created_at', 'updated_at', 'created_by', 'updated_by'], 'integer'],
            [['items'], 'string'],
            [['openid'], 'string', 'max' => 120],
            [['client_ip'], 'string', 'max' => 32],
            [['openid'], 'unique']
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app/ad', 'ID'),
            'save_id' => Yii::t('app/ad', 'Save ID'),
            'openid' => Yii::t('app/ad', 'Openid'),
            'items' => Yii::t('app/ad', 'Items'),
            'client_ip' => Yii::t('app/ad', 'Client Ip'),
            'created_at' => Yii::t('app/ad', 'Created At'),
            'updated_at' => Yii::t('app/ad', 'Updated At'),
            'created_by' => Yii::t('app/ad', 'Created By'),
            'updated_by' => Yii::t('app/ad', 'Updated By'),
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        $behaviors = parent::behaviors();

        $behaviors[] = [
            'class' => TimestampBehavior::className(),
            'createdAtAttribute' => 'created_at',
            'updatedAtAttribute' => 'updated_at',
            'value' => new Expression('NOW()'),
        ];

        return $behaviors;
    }
}
